package com.example.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import sun.security.krb5.internal.Ticket;

import java.util.List;

@RestController
@RequestMapping("/consumer")
public class UserController {

    @Autowired
    private RestTemplate restTemplate;

    private static final String PREFIX = "http://PROVIDER-TICKET";
    @RequestMapping("/selectAll")
    public List<Ticket> selectTicket() {
        //此参数为注册在Eureka中的服务
        //获取实体类
        //restTemplate.getForEntity();
        System.out.println("/consumer/select");
        System.out.println("in /consumer/select");
        return restTemplate.getForObject("http://provider-ticket/ticket/selectAll", List.class);//"http://PROVIDER-TICKET/ticket/selectAll"
    }
    @RequestMapping("/insertTicket")
    public boolean insertTicket(Ticket ticket){
        return restTemplate.postForObject(PREFIX+"/ticket/insertTicket",ticket, Boolean.class);
    }

    @RequestMapping("/getTicket/{id}")
    public Ticket getTicket(@PathVariable("id") Long id){
        return restTemplate.getForObject(PREFIX+"/ticket/getTicket/"+id,Ticket.class);
    }
    @RequestMapping("/fulian")
    public String ticket(){
        return "妇联4";
    }
}

